'''
Created on 2012-8-24

@author: null
'''
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

Model = declarative_base();
engine = None;
session = None;

def init_engine(app):
    if not app:
        raise Exception("app cannot be empty.");
    else:
        global session;
        global engine;
        connection_uri = app.config.get("CONNECTION_URI", None);
        engine = create_engine(connection_uri, pool_recycle=7200);
        Session = sessionmaker(bind=engine);
        session = Session();
        
def get_session():
    global session;
    return session;